package com.wjq.registration.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjq.registration.entity.*;
import com.wjq.registration.service.IDeskService;
import com.wjq.registration.service.IDistrictService;
import com.wjq.registration.service.IDoctorService;
import com.wjq.registration.service.IRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wjq
 * @since 2020-06-09
 */
@RestController
@RequestMapping("/record")
public class RecordController {
    @Autowired
    private IDistrictService iDistrictService;
    @Autowired
    private IRecordService iRecordService;
    @Autowired
    private IDeskService iDeskService;
    @Autowired
    private IDoctorService iDoctorService;


    @RequestMapping("desk")
    public List<Desk> desk(){
        List<Desk> list = iDeskService.list();
        return list;
    }

    @RequestMapping("type")
    public List<TypeVo> type(){
        TypeVo[] values = TypeVo.values();
        ArrayList<TypeVo> types = new ArrayList<>();
        for(TypeVo type:values){
            types.add(type);
        }
        return types;
    }

    @RequestMapping("doctor")
    public List<Doctor> doctor(Integer kid){
        QueryWrapper<Doctor> doctorQueryWrapper = new QueryWrapper<>();
        doctorQueryWrapper.eq("kid",kid);
        List<Doctor> list = iDoctorService.list(doctorQueryWrapper);
        return list;
    }

    @RequestMapping("ghprice")
    public List<GhpriceVo> ghprice(){
        GhpriceVo[] values = GhpriceVo.values();
        ArrayList<GhpriceVo> ghprices = new ArrayList<>();
        for(GhpriceVo ghprice:values){
            ghprices.add(ghprice);
        }
        return ghprices;
    }

    @RequestMapping("zlprice")
    public List<ZlpriceVo> zlprice(){
        ZlpriceVo[] values = ZlpriceVo.values();
        ArrayList<ZlpriceVo> zlprices = new ArrayList<>();
        for(ZlpriceVo zlprice:values){
            zlprices.add(zlprice);
        }
        return zlprices;
    }

    @RequestMapping("findRecord")
    public List<Record> list(String key){
        if(key==null&&"".equals(key)){
            return new ArrayList<>();
        }
        List<Record> byName = iRecordService.findByName(key);
        return byName;
    }

    @RequestMapping("findCity")
    public List<District> findCity(){
        return iDistrictService.findCity();
    }


    @RequestMapping("addPay")
    public Object addPay(@RequestBody Record r){
        r.setCreateTime(new Date());
        r.setStatus("已支付，未就诊");
        System.err.println(r);
        boolean save = iRecordService.save(r);

        return save;
    }

    @RequestMapping("findAll")
    public IPage<Record> list(@RequestParam(defaultValue = "1") Integer current,
                              @RequestParam(defaultValue = "5") Integer size, Record r){
        Page<Record> page = new Page<>(current, size);
        System.err.println(r);
        return iRecordService.findAll(page,r);
    }
}

